home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Workbench Add-On
/
Workbench Add-On - Volume 1.iso
/
Gfx
/
Conv
/
NetPBM
/
PBM_GUI
/
PBMGui.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-02-09
|
40KB
|
1,394 lines
// Freely distributable GadTools interface to PBM Plus
// mark@topic.demon.co.uk
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stddef.h>
#include <proto/exec.h>
#include <proto/gadtools.h>
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <proto/asl.h>
extern struct Library *GadToolsBase = NULL;
extern struct Library *AslBase = NULL;
#include <intuition/gadgetclass.h>
#include <dos/dostags.h>
#define GetString( g ) ((( struct StringInfo * )g->SpecialInfo )->Buffer )
#define GetNumber( g ) ((( struct StringInfo * )g->SpecialInfo )->LongInt )
#ifdef DEBUG
#define debug1(a) printf(a)
#define debug2(a,b) printf(a,b)
#else
#define debug1(a)
#define debug2(a,b)
#endif
#define HEAD_NONE 0
#define HEAD_LOAD 1
#define HEAD_PROCESS 2
#define HEAD_MISC 3
#define HEAD_SAVE 4
#define GAD_LFILE 1
#define GAD_SFILE 2
#define GAD_FILE 3
#define GAD_OFILE 4
#define GAD_ONUMBER 5
#define GAD_NUMBER 6
#define GAD_CYCLE 7
#define GAD_STRING 8
#define GAD_OSTRING 9
#define GAD_CHECK 10
struct TagItem ProcTags[] = {
{ SYS_Input, 0 },
{ SYS_Output, 0 },
{ NP_Error, 0 },
{ NP_CloseError, FALSE },
{ NP_StackSize, 50000 },
{ TAG_DONE }
};
struct MyType { // Load/Save etc.
struct List CList; // List of commands
short Number; // Number of commands
struct Gadget *Gadget; // Listview gadget
};
struct MyCommand { // A command
struct Node CNode; // In list of commands - holds Title of gadget
struct List GList; // List of gadgets
struct MyType *OwnType; // Owning type
char *Command; // Command to run
char *Comment; // Helpful comment
};
struct MyGadgetPtr {
struct MyGadget *MyGadget;
short Number;
};
struct MyGadget { // A gadget
struct Node GNode; // Used for list of gadgets on command
short Type; // Gadget type
struct List VList; // Used for values on cycle gadget
STRPTR *VStrings; // Used for strings on cycle gadget
struct MyCommand *OwnCommand; // Owning command
struct MyGadget *OwnCycle; // Owning cycle gadget
struct Gadget *Gadget1; // 1st gadget
struct Gadget *Gadget2; // 2nd gadget
struct Gadget *Gadget3; // 3rd gadget
long Activey; // Cycle value these are activated on
char *Title; // Title of gadget
char *Prefix; // Prefix for command
char *Defaults; // Default string;
long Defaultn; // Default number;
short Defaultc; // Default check;
long Defaulty; // Default cycle;
long Currentc; // Current check;
long Currenty; // Current cycle;
struct MyGadgetPtr Ptr1; // UserData points to one of these
struct MyGadgetPtr Ptr2;
struct MyGadgetPtr Ptr3;
};
struct MyValue {
struct Node VNode; // Used for list of cycle values;
char *Prefix; // Prefix for command
};
UWORD Zoom[] = {
0,0,
0,0
};
char Version[]="$VER: PBMGui 1.0 (9.2.94)";
char TempFileName[256];
struct FileRequester *filereq;
FILE *fp;
char buffer[256];
long linenumber = 0;
short heading=HEAD_NONE;
short FoundError=0;
short OutOfMemory = 0;
struct MyType Load,Process,Misc,Save;
struct MyType *CurrentType = NULL;
struct MyCommand *CurrentCommand = NULL;
struct MyGadget *CurrentGadget = NULL;
struct MyGadget *CurrentCycle = NULL;
struct MyValue *CurrentValue = NULL;
long CurrentCycleVal = -1;
/* Wait pointer */
static USHORT __chip BusyPointerData[] =
{
0x0000,0x0000,
0x0400,0x07C0,0x0000,0x07C0,0x0100,0x0380,0x0000,0x07E0,
0x07C0,0x1FF8,0x1FF0,0x3FEC,0x3FF8,0x7FDE,0x3FF8,0x7FBE,
0x7FFC,0xFF7F,0x7EFC,0xFFFF,0x7FFC,0xFFFF,0x3FF8,0x7FFE,
0x3FF8,0x7FFE,0x1FF0,0x3FFC,0x07C0,0x1FF8,0x0000,0x07E0,
0x0000,0x0000,
};
void pError(char *a,char *b);
void Command(void);
void ProcessGadget(void);
void ProcessCycle(void);
void GetTitle();
void GetParameter();
void GetStringDefault();
void GetNumberDefault();
void GetCheckDefault();
void GetDefCycle();
void GetCycleTitle();
void GetCycleParameter();
char *myfgets(void);
char *SkipSpace(char *s);
void RequesterStuff(struct MyCommand *MyCommand);
BOOL CreateGadgets(struct MyCommand *MyCommand);
BOOL GetAFile(UBYTE *name,char *Prompt,ULONG flags);
#define LISTHEIGHT 160
#define LISTWIDTH 148
void
main(int argc,char **argv) {
struct Screen *MyScreen;
struct TextAttr *MyTextAttr;
APTR MyVisInfo;
struct Gadget *MyContext;
struct Window *MyWindow;
struct IntuiMessage *MyIntuiMsg;
short Mynotdone = 1;
struct NewGadget MyNewGadget = {
0,0,
LISTWIDTH,LISTHEIGHT,
NULL,
NULL,
PLACETEXT_ABOVE,
NULL,
NULL
};
struct MyCommand *MyCommand;
struct MyType *MyType;
short Count = 0;
ULONG Secs=0;
ULONG Micros=0;
short LastGadget = -1;
struct MyType *LastType = NULL;
struct Requester MyRequest;
if (IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",37)) {
if (GadToolsBase = OpenLibrary("gadtools.library",37)) {
if (GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",37)) {
if (AslBase = OpenLibrary("asl.library",37)) {
if (filereq = AllocFileRequest()) {
NewList(&Load.CList);
Load.Number = 0;
NewList(&Process.CList);
Process.Number = 0;
NewList(&Misc.CList);
Misc.Number = 0;
NewList(&Save.CList);
Save.Number = 0;
if (fp = fopen("PROGDIR:PBMGui.config","r")) {
while (myfgets()) {
if (buffer[0] == '=') {
if (!strcmp(&buffer[1],"LOAD\n")) {
heading = HEAD_LOAD;
CurrentType = &Load;
}
else {
if (!strcmp(&buffer[1],"PROCESS\n")) {
heading = HEAD_PROCESS;
CurrentType = &Process;
}
else {
if (!strcmp(&buffer[1],"MISC\n")) {
heading = HEAD_MISC;
CurrentType = &Misc;
}
else {
if (!strcmp(&buffer[1],"SAVE\n")) {
heading = HEAD_SAVE;
CurrentType = &Save;
}
else {
heading = HEAD_NONE;
CurrentType = NULL;
pError("Invalid = header %s",&buffer[1]);
}
}
}
}
}
else {
if (buffer[0] == '\n') {
}
else {
if (buffer[0] == '"') {
Command();
}
}
}
}
if (!FoundError) {
if (MyScreen = LockPubScreen(NULL)) {
MyTextAttr = MyScreen->Font;
if (MyVisInfo = GetVisualInfo(MyScreen,NULL)) {
if (CreateContext(&MyContext)) {
MyNewGadget.ng_TopEdge = MyScreen->WBorTop + (MyScreen->Font->ta_YSize + 1 + INTERHEIGHT)*2;
MyNewGadget.ng_LeftEdge = MyScreen->WBorLeft + INTERWIDTH;
MyNewGadget.ng_VisualInfo = MyVisInfo;
MyNewGadget.ng_TextAttr = MyTextAttr;
MyNewGadget.ng_UserData = &(Load);
MyNewGadget.ng_GadgetText = "Load";
if (Load.Gadget = CreateGadget(LISTVIEW_KIND,MyContext,&MyNewGadget,
GTLV_Labels, &(Load.CList),
GTLV_ShowSelected,NULL,
TAG_END)) {
MyNewGadget.ng_UserData = &(Process);
MyNewGadget.ng_GadgetText = "Process";
MyNewGadget.ng_LeftEdge += LISTWIDTH + INTERWIDTH;
if (Process.Gadget = CreateGadget(LISTVIEW_KIND,Load.Gadget,&MyNewGadget,
GTLV_Labels, &(Process.CList),
GTLV_ShowSelected,NULL,
TAG_END)) {
MyNewGadget.ng_UserData = &(Misc);
MyNewGadget.ng_GadgetText = "Misc";
MyNewGadget.ng_LeftEdge += LISTWIDTH + INTERWIDTH;
if (Misc.Gadget = CreateGadget(LISTVIEW_KIND,Process.Gadget,&MyNewGadget,
GTLV_Labels, &(Misc.CList),
GTLV_ShowSelected,NULL,
TAG_END)) {
MyNewGadget.ng_UserData = &(Save);
MyNewGadget.ng_GadgetText = "Save";
MyNewGadget.ng_LeftEdge += LISTWIDTH + INTERWIDTH;
if (Save.Gadget = CreateGadget(LISTVIEW_KIND,Misc.Gadget,&MyNewGadget,
GTLV_Labels, &(Save.CList),
GTLV_ShowSelected,NULL,
TAG_END)) {
Zoom[0] = 0;
Zoom[1] = MyScreen->BarHeight+1;
Zoom[2] = 200;
Zoom[3] = MyScreen->WBorTop + MyScreen->Font->ta_YSize + 1;
if (MyWindow = OpenWindowTags(NULL,
WA_Flags, WFLG_DRAGBAR|
WFLG_DEPTHGADGET|
WFLG_CLOSEGADGET|
WFLG_SMART_REFRESH|
WFLG_ACTIVATE,
WA_IDCMP, BUTTONIDCMP|
IDCMP_CLOSEWINDOW|
IDCMP_REFRESHWINDOW|
LISTVIEWIDCMP,
WA_Width, (LISTWIDTH * 4 + INTERWIDTH * 5) +
MyScreen->WBorLeft + MyScreen->WBorRight,
WA_Height, LISTHEIGHT + MyScreen->WBorTop +
(MyScreen->Font->ta_YSize + 1)*2 + (INTERHEIGHT * 3),
WA_Title, "PBMGui",
WA_AutoAdjust, TRUE,
WA_PubScreen, MyScreen,
WA_Gadgets, MyContext,
WA_Zoom, Zoom,
TAG_END)) {
GT_RefreshWindow(MyWindow,NULL);
while (Mynotdone) {
WaitPort(MyWindow->UserPort);
while (MyIntuiMsg = GT_GetIMsg(MyWindow->UserPort)) {
switch (MyIntuiMsg->Class) {
case IDCMP_REFRESHWINDOW:
GT_BeginRefresh(MyWindow);
GT_EndRefresh(MyWindow,TRUE);
break;
case IDCMP_CLOSEWINDOW:
Mynotdone = 0;
break;
case IDCMP_GADGETUP:
MyType = (struct MyType *)((struct Gadget *)MyIntuiMsg->IAddress)->UserData;
if ((MyType == LastType) &&
(LastGadget == MyIntuiMsg->Code) &&
DoubleClick(Secs,Micros,MyIntuiMsg->Seconds,MyIntuiMsg->Micros)) {
Count = 0;
for (MyCommand = (struct MyCommand *)MyType->CList.lh_Head;
(Count != MyIntuiMsg->Code);
MyCommand = (struct MyCommand *)MyCommand->CNode.ln_Succ) {
++Count;
}
if (*MyCommand->Command != ' ') {
InitRequester(&MyRequest);
SetPointer(MyWindow, BusyPointerData, 16, 16, -6, 0);
if (Request(&MyRequest,MyWindow)) {
RequesterStuff(MyCommand);
EndRequest(&MyRequest,MyWindow);
}
ClearPointer(MyWindow);
}
}
LastType = MyType;
LastGadget = MyIntuiMsg->Code;
Secs = MyIntuiMsg->Seconds;
Micros = MyIntuiMsg->Micros;
break;
}
GT_ReplyIMsg(MyIntuiMsg);
}
}
CloseWindow(MyWindow);
}
}
}
}
}
FreeGadgets(MyContext);
}
FreeVisualInfo(MyVisInfo);
}
UnlockPubScreen(NULL,MyScreen);
}
}
fclose(fp);
}
FreeAslRequest(filereq);
}
CloseLibrary(AslBase);
}
CloseLibrary((struct Library *)GfxBase);
}
CloseLibrary(GadToolsBase);
}
CloseLibrary((struct Library *)IntuitionBase);
}
}
void
Command(void) {
char *s,*s1;
if (CurrentCommand = (struct MyCommand *)calloc(1,sizeof(struct MyCommand))) {
CurrentCommand->OwnType = CurrentType;
NewList(&CurrentCommand->GList);
if (CurrentType) {
AddTail(&CurrentType->CList,&CurrentCommand->CNode);
++CurrentType->Number;
}
}
else {
pError("Out of memory",NULL);
OutOfMemory = 1;
return;
}
s = strchr(&buffer[1],'"');
if (s) {
*s = 0;
CurrentCommand->Command = strdup(&buffer[1]);
while ((s = myfgets()) && !strchr(buffer,'"')) {
}
if (s) {
s = strchr(buffer,'"');
s1 = strchr(s+1,'"');
if (s1) {
*s1=0;
CurrentCommand->Comment = strdup(s+1);
if (myfgets()) {
s = strchr(buffer,'"');
if (s) {
s1 = strchr(s+1,'"');
if (s1) {
*s1=0;
CurrentCommand->CNode.ln_Name = strdup(s+1);
while (myfgets() && (buffer[0] != '\n')) {
ProcessGadget();
}
}
else {
pError("No trailing \" on 'Title' line",NULL);
while (myfgets() && (buffer[0] != '\n')) {
}
}
}
else {
pError("No starting \" on 'Title' line",NULL);
while (myfgets() && (buffer[0] != '\n')) {
}
}
}
else {
pError("Unexpected end of file - missing Title",NULL);
}
}
else {
pError("No trailing \" on 'Comment' line",NULL);
while (myfgets() && (buffer[0] != '\n')) {
}
}
}
else {
pError("Unexpected end of file - Missin Comment",NULL);
}
}
else {
pError("No trailing \" on 'Command' line",NULL);
while (myfgets() && (buffer[0] != '\n')) {
}
}
CurrentCommand = NULL;
}
void
pError(char *a,char *b) {
if (!OutOfMemory) {
printf("Error on line %ld\n",linenumber);
printf(a,b);
printf("\n");
++FoundError;
}
}
char
*myfgets(void) {
char *s;
if ((FoundError > 10) || (OutOfMemory)) {
printf("Too many errors - giving up!!!\n");
return NULL;
}
++linenumber;
while ((s = fgets(buffer,255,fp)) && (buffer[0] == '*')) {
++linenumber;
}
return s;
}
void
ProcessGadget(void) {
char *s;
if (CurrentGadget = (struct MyGadget *)calloc(1,sizeof(struct MyGadget))) {
CurrentGadget->OwnCommand = CurrentCommand;
NewList(&CurrentGadget->VList);
if (CurrentCommand) {
AddTail(&CurrentCommand->GList,&CurrentGadget->GNode);
}
if (CurrentCycle) {
CurrentGadget->Activey = CurrentCycleVal;
CurrentGadget->OwnCycle = CurrentCycle;
}
}
else {
pError("Out of memory",NULL);
OutOfMemory = 1;
return;
}
s = SkipSpace(buffer);
if (s) {
if (!strncmp(s,"LFILE",strlen("LFILE"))) {
CurrentGadget->Type = GAD_LFILE;
GetTitle();
GetParameter();
GetStringDefault();
}
else {
if (!strncmp(s,"SFILE",strlen("SFILE"))) {
CurrentGadget->Type = GAD_SFILE;
GetTitle();
GetParameter();
GetStringDefault();
}
else {
if (!strncmp(s,"FILE",strlen("FILE"))) {
CurrentGadget->Type = GAD_FILE;
GetTitle();
GetParameter();
GetStringDefault();
}
else {
if (!strncmp(s,"OFILE",strlen("OFILE"))) {
CurrentGadget->Type = GAD_OFILE;
GetTitle();
GetParameter();
GetStringDefault();
GetCheckDefault();
}
else {
if (!strncmp(s,"ONUMBER",strlen("ONUMBER"))) {
CurrentGadget->Type = GAD_ONUMBER;
GetTitle();
GetParameter();
GetNumberDefault();
GetCheckDefault();
}
else {
if (!strncmp(s,"NUMBER",strlen("NUMBER"))) {
CurrentGadget->Type = GAD_NUMBER;
GetTitle();
GetParameter();
GetNumberDefault();
}
else {
if (!strncmp(s,"CYCLE",strlen("CYCLE"))) {
CurrentGadget->Type = GAD_CYCLE;
if (CurrentCycle) {
pError("Cannot have CYCLE in CYCLE",NULL);
}
else {
GetTitle();
ProcessCycle();
}
}
else {
if (!strncmp(s,"STRING",strlen("STRING"))) {
CurrentGadget->Type = GAD_STRING;
GetTitle();
GetParameter();
GetStringDefault();
}
else {
if (!strncmp(s,"OSTRING",strlen("OSTRING"))) {
CurrentGadget->Type = GAD_OSTRING;
GetTitle();
GetParameter();
GetStringDefault();
GetCheckDefault();
}
else {
if (!strncmp(s,"CHECK",strlen("CHECK"))) {
CurrentGadget->Type = GAD_CHECK;
GetTitle();
GetParameter();
GetCheckDefault();
}
else {
pError("Unknown gadget type",s);
while(myfgets() && (buffer[0] != '\n')) {
}
}
}
}
}
}
}
}
}
}
}
}
else {
pError("Unexpcted space filled line",NULL);
}
CurrentGadget = NULL;
}
void
ProcessCycle(void) {
char *s;
short endfound = 0;
short first = 1;
short StringCount = 0;
struct MyValue *MyValue;
STRPTR *ptr;
CurrentCycle = CurrentGadget;
CurrentCycleVal = -1;
while (!endfound && myfgets()) {
s = SkipSpace(buffer);
if (s) {
if (*s == '"') {
first = 0;
if (CurrentValue = (struct MyValue *)calloc(1,sizeof(struct MyValue))) {
AddTail(&CurrentCycle->VList,&CurrentValue->VNode);
GetCycleTitle();
GetCycleParameter();
CurrentValue = NULL;
++StringCount;
++CurrentCycleVal;
}
else {
pError("Out of memory",NULL);
OutOfMemory = 1;
return;
}
}
else {
if (!first) {
if (!strncmp(s,"ENDCYCLE",strlen("ENDCYCLE"))) {
GetDefCycle();
endfound = 1;
}
else {
ProcessGadget();
}
}
else {
pError("Missing first cycle gadget text",NULL);
while (myfgets() && (buffer[0] != '\n')) {
}
}
}
}
else {
pError("Unexpected space line - Missing ENDCYCLE",NULL);
return;
}
}
if (!endfound) {
pError("Unexpected end of file - Missing ENDCYCLE",NULL);
}
if (ptr = CurrentCycle->VStrings = (STRPTR *)calloc(sizeof(STRPTR),StringCount+1)) {
for (MyValue = (struct MyValue *)CurrentCycle->VList.lh_Head;
MyValue->VNode.ln_Succ;
MyValue = (struct MyValue *)MyValue->VNode.ln_Succ) {
*ptr = MyValue->VNode.ln_Name;
ptr++;
}
}
else {
pError("Out of memory",NULL);
OutOfMemory = 1;
return;
}
CurrentCycle = NULL;
}
char *CurrentPos;
void
GetTitle() {
char *s;
CurrentPos = strchr(buffer,'"');
if (CurrentPos) {
s = CurrentPos + 1;
CurrentPos = strchr(s,'"');
if (CurrentPos) {
*CurrentPos = 0;
CurrentGadget->Title = strdup(s);
++CurrentPos;
}
else {
pError("Missing gadget Title end \"",NULL);
}
}
else {
pError("Missing gadget Title start \"",NULL);
}
}
void
GetParameter() {
char *s;
if (CurrentPos) {
CurrentPos = strchr(CurrentPos,'"');
if (CurrentPos) {
s = CurrentPos + 1;
CurrentPos = strchr(s,'"');
if (CurrentPos) {
*CurrentPos = 0;
CurrentGadget->Prefix = strdup(s);
++CurrentPos;
}
else {
pError("Missing gadget Prefix end \"",NULL);
}
}
else {
pError("Missing gadget Prefix start \"",NULL);
}
}
}
char *NullString = "";
void
GetStringDefault() {
char *s;
if (CurrentPos) {
CurrentPos = strchr(CurrentPos,'"');
if (CurrentPos) {
s = CurrentPos + 1;
CurrentPos = strchr(s,'"');
if (CurrentPos) {
*CurrentPos = 0;
CurrentGadget->Defaults = strdup(s);
++CurrentPos;
}
else {
pError("Missing gadget Default end \"",NULL);
}
}
else {
CurrentGadget->Defaults = NullString;
}
}
else {
CurrentGadget->Defaults = NullString;
}
}
void
GetNumberDefault() {
char *s;
long number;
if (CurrentPos) {
CurrentPos = strchr(CurrentPos,'"');
if (CurrentPos) {
s = CurrentPos + 1;
CurrentPos = strchr(s,'"');
if (CurrentPos) {
*CurrentPos = 0;
number = strtol(s,&CurrentPos,10);
CurrentGadget->Defaultn = number;
++CurrentPos;
}
else {
pError("Missing gadget Default end \"",NULL);
}
}
else {
number = 0;
CurrentGadget->Defaultn = number;
}
}
else {
number = 0;
CurrentGadget->Defaultn = number;
}
}
void
GetCheckDefault() {
char *s;
short Check;
if (CurrentPos) {
s = strpbrk(CurrentPos,"YN");
if (s && *s) {
if (*s == 'Y') {
Check = 1;
CurrentGadget->Defaultc = Check;
}
else {
Check = 0;
CurrentGadget->Defaultc = Check;
}
}
else {
Check = 0;
CurrentGadget->Defaultc = Check;
}
}
else {
Check = 0;
CurrentGadget->Defaultc = Check;
}
CurrentGadget->Currentc = CurrentGadget->Defaultc;
}
void
GetDefCycle() {
char *s;
long number;
CurrentPos = strchr(buffer,'"');
if (CurrentPos) {
s = CurrentPos + 1;
CurrentPos = strchr(s,'"');
if (CurrentPos) {
*CurrentPos = 0;
number = strtol(s,&CurrentPos,10);
CurrentCycle->Defaulty = number;
++CurrentPos;
}
else {
pError("Missing gadget Default end \"",NULL);
}
}
else {
number = 0;
CurrentCycle->Defaulty = number;
}
CurrentCycle->Currenty = CurrentCycle->Defaulty;
}
void
GetCycleTitle() {
char *s;
CurrentPos = strchr(buffer,'"');
if (CurrentPos) {
s = CurrentPos + 1;
CurrentPos = strchr(s,'"');
if (CurrentPos) {
*CurrentPos = 0;
CurrentValue->VNode.ln_Name = strdup(s);
++CurrentPos;
}
else {
pError("Missing Cycle Value end \"",NULL);
}
}
else {
pError("Missing Cycle Value start \"",NULL);
}
}
void
GetCycleParameter() {
char *s;
if (CurrentPos) {
CurrentPos = strchr(CurrentPos,'"');
if (CurrentPos) {
s = CurrentPos + 1;
CurrentPos = strchr(s,'"');
if (CurrentPos) {
*CurrentPos = 0;
CurrentValue->Prefix = strdup(s);
++CurrentPos;
}
else {
pError("Missing Cycle value Prefix end \"",NULL);
}
}
else {
pError("Missing Cycle value Prefix start \"",NULL);
}
}
}
char
*SkipSpace(char *s) {
while (s && *s && ((*s == ' ') || (*s == '\t'))) {
++s;
}
return s;
}
#define LEFT 15
#define RIGHT 30
struct Screen *Screen;
struct TextAttr *TextAttr;
APTR VisInfo;
struct Gadget *Context;
struct Window *Window;
struct Requester Requestx;
struct IntuiMessage *IntuiMsg;
long height = 0;
UWORD width = 0;
BOOL File1 = TRUE;
char Buffer[1024];
char tBuffer[256];
void
RequesterStuff(struct MyCommand *MyCommand) {
struct MyGadgetPtr *Ptr;
struct MyGadget *MyGadget,*LoopGadget;
struct MyValue *MyValue;
short count;
short notdone = 1;
if (Screen = LockPubScreen(NULL)) {
TextAttr = Screen->Font;
if (VisInfo = GetVisualInfo(Screen,NULL)) {
if (CreateContext(&Context)) {
if (CreateGadgets(MyCommand)) {
if (Window = OpenWindowTags(NULL,
WA_Flags, WFLG_DRAGBAR|
WFLG_DEPTHGADGET|
WFLG_CLOSEGADGET|
WFLG_SMART_REFRESH|
WFLG_ACTIVATE,
WA_IDCMP, BUTTONIDCMP|
IDCMP_CLOSEWINDOW|
IDCMP_REFRESHWINDOW,
WA_Width, width * (LEFT + RIGHT) + (INTERWIDTH * 2) +
Screen->WBorLeft +
Screen->WBorRight,
WA_Height, height,
WA_Title, MyCommand->Comment,
WA_AutoAdjust, TRUE,
WA_PubScreen, Screen,
WA_Gadgets, Context,
WA_Zoom, Zoom,
TAG_END)) {
GT_RefreshWindow(Window,NULL);
while (notdone) {
WaitPort(Window->UserPort);
while (IntuiMsg = GT_GetIMsg(Window->UserPort)) {
switch (IntuiMsg->Class) {
case IDCMP_REFRESHWINDOW:
GT_BeginRefresh(Window);
GT_EndRefresh(Window,TRUE);
break;
case IDCMP_CLOSEWINDOW:
if ((MyCommand->OwnType == &Process)) {
File1 = !File1;
}
notdone = 0;
break;
case IDCMP_GADGETUP:
Ptr = (struct MyGadgetPtr *)((struct Gadget *)IntuiMsg->IAddress)->UserData;
if (!Ptr) {
sprintf(Buffer,"%s",MyCommand->Command);
for (LoopGadget = (struct MyGadget *)(MyCommand->GList.lh_Head);
LoopGadget->GNode.ln_Succ;
LoopGadget = (struct MyGadget *)(LoopGadget->GNode.ln_Succ)) {
if (!LoopGadget->OwnCycle || (LoopGadget->OwnCycle->Currenty == LoopGadget->Activey)) {
switch (LoopGadget->Type) {
case GAD_LFILE:
case GAD_SFILE:
case GAD_FILE:
sprintf(tBuffer,"%s\"%s\" ",LoopGadget->Prefix,GetString(LoopGadget->Gadget1));
strcat(Buffer,tBuffer);
break;
case GAD_OFILE:
if (LoopGadget->Currentc) {
sprintf(tBuffer,"%s\"%s\" ",LoopGadget->Prefix,GetString(LoopGadget->Gadget2));
strcat(Buffer,tBuffer);
}
break;
case GAD_ONUMBER:
if (LoopGadget->Currentc) {
sprintf(tBuffer,"%s%ld ",LoopGadget->Prefix,GetNumber(LoopGadget->Gadget2));
strcat(Buffer,tBuffer);
}
break;
case GAD_NUMBER:
sprintf(tBuffer,"%s%ld ",LoopGadget->Prefix,GetNumber(LoopGadget->Gadget1));
strcat(Buffer,tBuffer);
break;
case GAD_CYCLE:
count = 0;
for (MyValue = (struct MyValue *)(LoopGadget->VList.lh_Head);
MyValue->VNode.ln_Succ;
MyValue = (struct MyValue *)(MyValue->VNode.ln_Succ)){
if (count == LoopGadget->Currenty) {
sprintf(tBuffer,"%s ",MyValue->Prefix);
strcat(Buffer,tBuffer);
}
++count;
}
break;
case GAD_STRING:
sprintf(tBuffer,"%s%s ",LoopGadget->Prefix,GetString(LoopGadget->Gadget1));
strcat(Buffer,tBuffer);
break;
case GAD_OSTRING:
if (LoopGadget->Currentc) {
sprintf(tBuffer,"%s%s ",LoopGadget->Prefix,GetString(LoopGadget->Gadget2));
strcat(Buffer,tBuffer);
}
break;
case GAD_CHECK:
if (LoopGadget->Currentc) {
sprintf(tBuffer,"%s ",LoopGadget->Prefix);
strcat(Buffer,tBuffer);
}
break;
}
}
}
InitRequester(&Requestx);
SetPointer(Window, BusyPointerData, 16, 16, -6, 0);
if (Request(&Requestx,Window)) {
ProcTags[0].ti_Data = Input();
ProcTags[1].ti_Data = Output();
ProcTags[2].ti_Data = Output();
if (SystemTagList(Buffer,ProcTags)) {
// if command fails then switch back to original
if ((MyCommand->OwnType == &Process)) {
File1 = !File1;
}
}
EndRequest(&Requestx,Window);
}
ClearPointer(Window);
notdone = 0;
}
else {
MyGadget = Ptr->MyGadget;
switch (MyGadget->Type) {
case GAD_LFILE:
case GAD_SFILE:
case GAD_FILE:
switch (Ptr->Number) {
case 2:
if (GetAFile(GetString(MyGadget->Gadget1),
(MyGadget->Type == GAD_LFILE)?"Select input file":
(MyGadget->Type == GAD_SFILE)?"Select output file":
"Select file",
(MyGadget->Type == GAD_SFILE)?FILF_SAVE:0)) {
GT_SetGadgetAttrs(MyGadget->Gadget1,Window,NULL,
GTST_String,TempFileName,
TAG_END);
}
break;
}
break;
case GAD_OFILE:
switch (Ptr->Number) {
case 1:
MyGadget->Currentc = !MyGadget->Currentc;
GT_SetGadgetAttrs(MyGadget->Gadget2,Window,NULL,
GA_Disabled,!MyGadget->Currentc,
TAG_END);
GT_SetGadgetAttrs(MyGadget->Gadget3,Window,NULL,
GA_Disabled,!MyGadget->Currentc,
TAG_END);
if (MyGadget->Currentc) {
ActivateGadget(MyGadget->Gadget2,Window,NULL);
}
break;
case 3:
if (GetAFile(GetString(MyGadget->Gadget2),
"Select file",0)) {
GT_SetGadgetAttrs(MyGadget->Gadget2,Window,NULL,
GTST_String,TempFileName,
TAG_END);
}
break;
}
break;
case GAD_ONUMBER:
switch (Ptr->Number) {
case 1:
MyGadget->Currentc = !MyGadget->Currentc;
GT_SetGadgetAttrs(MyGadget->Gadget2,Window,NULL,
GA_Disabled,!MyGadget->Currentc,
TAG_END);
if (MyGadget->Currentc) {
ActivateGadget(MyGadget->Gadget2,Window,NULL);
}
break;
}
break;
case GAD_NUMBER:
break;
case GAD_CYCLE:
MyGadget->Currenty = IntuiMsg->Code;
for (LoopGadget = (struct MyGadget *)(MyGadget->OwnCommand->GList.lh_Head);
LoopGadget->GNode.ln_Succ;
LoopGadget = (struct MyGadget *)(LoopGadget->GNode.ln_Succ)){
if (MyGadget == LoopGadget->OwnCycle) {
GT_SetGadgetAttrs(LoopGadget->Gadget1,Window,NULL,
GA_Disabled,MyGadget->Currenty != LoopGadget->Activey,
TAG_END);
if (LoopGadget->Gadget2) {
GT_SetGadgetAttrs(LoopGadget->Gadget2,Window,NULL,
GA_Disabled,(MyGadget->Currenty != LoopGadget->Activey) |
(((LoopGadget->Type == GAD_ONUMBER) |
(LoopGadget->Type == GAD_OSTRING) |
(LoopGadget->Type == GAD_OFILE)) & (!LoopGadget->Currentc)),
TAG_END);
}
if (LoopGadget->Gadget3) {
GT_SetGadgetAttrs(LoopGadget->Gadget3,Window,NULL,
GA_Disabled,(MyGadget->Currenty != LoopGadget->Activey) |
((LoopGadget->Type == GAD_OFILE) & (!LoopGadget->Currentc)),
TAG_END);
}
}
}
break;
case GAD_STRING:
break;
case GAD_OSTRING:
switch (Ptr->Number) {
case 1:
MyGadget->Currentc = !MyGadget->Currentc;
GT_SetGadgetAttrs(MyGadget->Gadget2,Window,NULL,
GA_Disabled,!MyGadget->Currentc,
TAG_END);
if (MyGadget->Currentc) {
ActivateGadget(MyGadget->Gadget2,Window,NULL);
}
break;
}
break;
case GAD_CHECK:
MyGadget->Currentc = !MyGadget->Currentc;
break;
}
}
break;
default:
break;
}
GT_ReplyIMsg(IntuiMsg);
}
}
CloseWindow(Window);
}
}
FreeGadgets(Context);
}
FreeVisualInfo(VisInfo);
}
UnlockPubScreen(NULL,Screen);
}
}
BOOL
CreateGadgets(struct MyCommand *MyCommand) {
struct MyGadget *MyGadget;
struct Gadget *Gadget;
struct NewGadget NewGadget = {
0,0,
0,0,
NULL,
NULL,
PLACETEXT_IN,
NULL,
NULL
};
char *string;
width = min(Screen->Font->ta_YSize,8);
Gadget = Context;
height = Screen->WBorTop + Screen->Font->ta_YSize + 1;
NewGadget.ng_Height = Screen->Font->ta_YSize + 4;
NewGadget.ng_VisualInfo = VisInfo;
NewGadget.ng_TextAttr = TextAttr;
if (MyCommand) {
for (MyGadget = (struct MyGadget *)MyCommand->GList.lh_Head;
MyGadget->GNode.ln_Succ && Gadget;
MyGadget = (struct MyGadget *)MyGadget->GNode.ln_Succ) {
height += INTERHEIGHT;
NewGadget.ng_TopEdge = height;
switch (MyGadget->Type) {
case GAD_LFILE:
case GAD_SFILE:
case GAD_FILE:
if (MyGadget->Type == GAD_FILE) {
string = MyGadget->Defaults;
}
else {
if (MyGadget->Type == GAD_LFILE) {
if (MyCommand->OwnType != &Load) {
if (File1) {
string = "T:PBM_GUI_1";
}
else {
string = "T:PBM_GUI_2";
}
if (MyCommand->OwnType == &Process) {
File1 = !File1;
}
}
else {
string = "";
}
}
else {
if (MyCommand->OwnType != &Save) {
if (File1) {
string = "T:PBM_GUI_1";
}
else {
string = "T:PBM_GUI_2";
}
}
else {
string = "";
}
}
}
MyGadget->Ptr1.MyGadget = MyGadget;
MyGadget->Ptr1.Number = 1;
NewGadget.ng_UserData = &(MyGadget->Ptr1);
NewGadget.ng_LeftEdge = Screen->WBorLeft + INTERWIDTH + width*LEFT;
NewGadget.ng_Width = width*RIGHT - INTERWIDTH - 26;
NewGadget.ng_GadgetText = MyGadget->Title;
MyGadget->Gadget1 = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
GTST_String, string,
GTST_MaxChars, 128,
GA_Disabled, MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE,
TAG_END);
NewGadget.ng_LeftEdge += NewGadget.ng_Width + INTERWIDTH;
MyGadget->Ptr2.MyGadget = MyGadget;
MyGadget->Ptr2.Number = 2;
NewGadget.ng_UserData = &(MyGadget->Ptr2);
NewGadget.ng_Width = 26;
NewGadget.ng_GadgetText = "«";
MyGadget->Gadget2 = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
GA_Disabled, MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE,
TAG_END);
break;
case GAD_OFILE:
MyGadget->Ptr1.MyGadget = MyGadget;
MyGadget->Ptr1.Number = 1;
NewGadget.ng_UserData = &(MyGadget->Ptr1);
NewGadget.ng_LeftEdge = Screen->WBorLeft + INTERWIDTH + width*LEFT;
NewGadget.ng_Width = 26;
NewGadget.ng_GadgetText = MyGadget->Title;
MyGadget->Gadget1 = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
GTCB_Checked, MyGadget->Currentc,
GA_Disabled, MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE,
TAG_END);
MyGadget->Ptr2.MyGadget = MyGadget;
MyGadget->Ptr2.Number = 2;
NewGadget.ng_UserData = &(MyGadget->Ptr2);
NewGadget.ng_LeftEdge += INTERWIDTH + 26;
NewGadget.ng_Width = width*RIGHT - ((INTERWIDTH + 26) * 2);
NewGadget.ng_GadgetText = NULL;
MyGadget->Gadget2 = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
GTST_String, MyGadget->Defaults,
GTST_MaxChars, 128,
GA_Disabled,MyGadget->Currentc ? (MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE) : TRUE,
TAG_END);
NewGadget.ng_LeftEdge += NewGadget.ng_Width + INTERWIDTH;
MyGadget->Ptr3.MyGadget = MyGadget;
MyGadget->Ptr3.Number = 3;
NewGadget.ng_UserData = &(MyGadget->Ptr3);
NewGadget.ng_Width = 26;
NewGadget.ng_GadgetText = "«";
MyGadget->Gadget3 = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
GA_Disabled,MyGadget->Currentc ? (MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE) : TRUE,
TAG_END);
break;
case GAD_ONUMBER:
MyGadget->Ptr1.MyGadget = MyGadget;
MyGadget->Ptr1.Number = 1;
NewGadget.ng_UserData = &(MyGadget->Ptr1);
NewGadget.ng_LeftEdge = Screen->WBorLeft + INTERWIDTH + width*LEFT;
NewGadget.ng_Width = 26;
NewGadget.ng_GadgetText = MyGadget->Title;
MyGadget->Gadget1 = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
GTCB_Checked, MyGadget->Currentc,
GA_Disabled, MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE,
TAG_END);
MyGadget->Ptr2.MyGadget = MyGadget;
MyGadget->Ptr2.Number = 2;
NewGadget.ng_UserData = &(MyGadget->Ptr2);
NewGadget.ng_LeftEdge += INTERWIDTH + 26;
NewGadget.ng_Width = width*RIGHT - 26 - INTERWIDTH;
NewGadget.ng_GadgetText = NULL;
MyGadget->Gadget2 = Gadget = CreateGadget(INTEGER_KIND,Gadget,&NewGadget,
GTIN_Number, MyGadget->Defaultn,
GA_Disabled,MyGadget->Currentc ? (MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE) : TRUE,
TAG_END);
break;
case GAD_NUMBER:
MyGadget->Ptr1.MyGadget = MyGadget;
MyGadget->Ptr1.Number = 1;
NewGadget.ng_UserData = &(MyGadget->Ptr1);
NewGadget.ng_LeftEdge = Screen->WBorLeft + INTERWIDTH + width*LEFT;
NewGadget.ng_Width = width*RIGHT;
NewGadget.ng_GadgetText = MyGadget->Title;
MyGadget->Gadget1 = Gadget = CreateGadget(INTEGER_KIND,Gadget,&NewGadget,
GTIN_Number, MyGadget->Defaultn,
GA_Disabled, MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE,
TAG_END);
break;
case GAD_CYCLE:
MyGadget->Ptr1.MyGadget = MyGadget;
MyGadget->Ptr1.Number = 1;
NewGadget.ng_UserData = &(MyGadget->Ptr1);
NewGadget.ng_LeftEdge = Screen->WBorLeft + INTERWIDTH + width*LEFT;
NewGadget.ng_Width = width*RIGHT;
NewGadget.ng_GadgetText = MyGadget->Title;
MyGadget->Gadget1 = Gadget = CreateGadget(CYCLE_KIND,Gadget,&NewGadget,
GTCY_Labels, MyGadget->VStrings,
GTCY_Active, MyGadget->Currenty,
TAG_END);
break;
case GAD_STRING:
MyGadget->Ptr1.MyGadget = MyGadget;
MyGadget->Ptr1.Number = 1;
NewGadget.ng_UserData = &(MyGadget->Ptr1);
NewGadget.ng_LeftEdge = Screen->WBorLeft + INTERWIDTH + width*LEFT;
NewGadget.ng_Width = width*RIGHT;
NewGadget.ng_GadgetText = MyGadget->Title;
MyGadget->Gadget1 = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
GTST_String, MyGadget->Defaults,
GA_Disabled, MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE,
TAG_END);
break;
case GAD_OSTRING:
MyGadget->Ptr1.MyGadget = MyGadget;
MyGadget->Ptr1.Number = 1;
NewGadget.ng_UserData = &(MyGadget->Ptr1);
NewGadget.ng_LeftEdge = Screen->WBorLeft + INTERWIDTH + width*LEFT;
NewGadget.ng_Width = 26;
NewGadget.ng_GadgetText = MyGadget->Title;
MyGadget->Gadget1 = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
GTCB_Checked, MyGadget->Currentc,
GA_Disabled, MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE,
TAG_END);
MyGadget->Ptr2.MyGadget = MyGadget;
MyGadget->Ptr2.Number = 2;
NewGadget.ng_UserData = &(MyGadget->Ptr2);
NewGadget.ng_LeftEdge += INTERWIDTH + 26;
NewGadget.ng_Width = width*RIGHT - 26 - INTERWIDTH;
NewGadget.ng_GadgetText = NULL;
MyGadget->Gadget2 = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
GTST_String, MyGadget->Defaults,
GA_Disabled,MyGadget->Currentc ? (MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE) : TRUE,
TAG_END);
break;
case GAD_CHECK:
MyGadget->Ptr1.MyGadget = MyGadget;
MyGadget->Ptr1.Number = 1;
NewGadget.ng_UserData = &(MyGadget->Ptr1);
NewGadget.ng_LeftEdge = Screen->WBorLeft + INTERWIDTH + width*LEFT;
NewGadget.ng_Width = 26;
NewGadget.ng_GadgetText = MyGadget->Title;
MyGadget->Gadget1 = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
GTCB_Checked, MyGadget->Currentc,
GA_Disabled, MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE,
TAG_END);
break;
}
height += Screen->Font->ta_YSize + 2;
}
height += INTERHEIGHT;
NewGadget.ng_TopEdge = height;
NewGadget.ng_UserData = NULL;
NewGadget.ng_LeftEdge = Screen->WBorLeft + INTERWIDTH;
NewGadget.ng_Width = width * (LEFT+RIGHT);
NewGadget.ng_GadgetText = "Perform";
Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
TAG_END);
height += Screen->Font->ta_YSize + 2;
}
height += Screen->WBorBottom + INTERHEIGHT;
return (BOOL)Gadget;
}
/* Shows ASL file requester for a file
* name : current file name
* Prompt: Title
* flags : e.g. for save flag
* Returns: TRUE if file selected, name is TempFileName
*/
BOOL
GetAFile(UBYTE *name,char *Prompt,ULONG flags) {
// Split of directory name
strncpy(TempFileName,name,(UBYTE *)PathPart(name) - (UBYTE *)name);
TempFileName[(UBYTE *)PathPart(name) - (UBYTE *)name] = 0;
// Show requesters
InitRequester(&Requestx);
SetPointer(Window, BusyPointerData, 16, 16, -6, 0);
if (Request(&Requestx,Window)) {
if (AslRequestTags((APTR) filereq,
ASL_Hail,(Tag) Prompt,
ASL_FuncFlags,flags,
ASL_Dir, (Tag) TempFileName,
ASL_File,(Tag) FilePart(name),
ASL_Window, Window,
TAG_DONE)) {
// rejoin name
strncpy(TempFileName,filereq->rf_Dir,256);
AddPart(TempFileName,filereq->rf_File,256);
ClearPointer(Window);
EndRequest(&Requestx,Window);
return TRUE;
}
else {
ClearPointer(Window);
EndRequest(&Requestx,Window);
return FALSE;
}
}
else {
return FALSE;
}
}